from django.db import models
from datetime import datetime
CATEGORY = (
    ('training','培训机构'),
    ('private','个人'),
    ('university','高校'),
)
class City(models.Model):
    name = models.CharField(max_length=100, verbose_name='城市')
    desc = models.CharField(max_length=200, verbose_name='描述')
    add_time = models.DateTimeField(default=datetime.now)
    class Meta:
        verbose_name = '城市'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

# Create your models here.
class CourseOrg(models.Model):
    name = models.CharField(max_length=100,verbose_name='机构名称')
    desc = models.TextField(verbose_name='机构描述')
    click_nums = models.IntegerField(default=0,verbose_name='点击数')
    category = models.CharField(choices=CATEGORY,verbose_name='机构类别',default='training',max_length=50)
    fav_nums = models.IntegerField(default=0,verbose_name='收藏数')
    image = models.ImageField(upload_to='org/%Y/%m',verbose_name='封面图片',max_length=200)
    address = models.CharField(max_length=200,verbose_name='机构地址')
    city = models.ForeignKey(City,verbose_name='所在城市')
    students = models.IntegerField(default=0,verbose_name='学习人数')
    course_nums = models.IntegerField(default=0,verbose_name='课程数')
    add_time = models.DateTimeField(default=datetime.now)
    class Meta:
        verbose_name = '课程机构'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name
    #统计机构教师数量
    def teachers_num(self):
        return self.teacher_set.all().count()

class Teacher(models.Model):
    org = models.ForeignKey(CourseOrg,verbose_name='所属单位')
    name = models.CharField(max_length=100,verbose_name='教师名称')
    image = models.ImageField(upload_to='teacher/%Y/%m',verbose_name='教师图片',max_length=200,null=True,blank=True)
    desc = models.TextField(verbose_name='教师简介',default='')
    work_year = models.IntegerField(default=0, verbose_name='工作年限')
    work_company = models.CharField(max_length=100, verbose_name='工作单位')
    work_position = models.CharField(max_length=100, verbose_name='工作职位')
    points = models.CharField(max_length=100, verbose_name='教学特点')
    click_nums = models.IntegerField(default=0, verbose_name='点击数')
    age = models.IntegerField(default=18, verbose_name='年龄')
    fav_nums = models.IntegerField(default=0, verbose_name='收藏数')
    add_time = models.DateTimeField(default=datetime.now,verbose_name='添加时间')
    class Meta:
        verbose_name = '教师'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name
    def get_course_nums(self):
        return self.course_set.all().count()